import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;


public class longestString {

	String Short, Long;
    String Input1, Input2;
    StringBuffer myStr = new StringBuffer();
    Object testStr;
    LinkedList<String> newList = new LinkedList();
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
 
    public String LCM(String s1, String s2){
 
        int i = 0;
        int j = 0;
        while(i < s1.length() && j < s2.length()){
            if(s1.charAt(i) == s2.charAt(j)){              
               myStr.append(s1.charAt(i));
               j++;
            }
            else{
                if ( s1.charAt(i) != s2.charAt(j)){
                    i++;
                }
            }
        }
      String opt = new String(getMyStr());
       return  opt;
    }
 
    public LinkedList allCombinations(String givenStr){
        LinkedList myStrings = new LinkedList();
        for (int i = 0; i < givenStr.length(); i++){
            String newStr = givenStr.substring(i, givenStr.length());
            myStrings.add(newStr);            
        }
        return myStrings;
    }
 
    public LinkedList compare(LinkedList myList){
        while(!myList.isEmpty()){
            testStr = myList.pop();
            String thisStr = String.valueOf(testStr);
            newList.add(this.LCM(Long, thisStr));
 
        }
        return newList;
    }
 
    /** Creates a new instance of longestString */
    public longestString() throws IOException{
        System.out.println("please Enter the First String");
        Input1 = in.readLine();
        System.out.println("please Enter the Second String");
        Input2 = in.readLine();
 
         if (Input1.length() < Input2.length()){
            Short = Input1;
            Long = Input2;
        } else if (Input1.length() > Input2.length()){
            Long = Input1;
            Short = Input2;
        }else {
            Long = Input1;
            Short = Input2;
        }// end if-else statements
 
       // System.out.println("Long String = " + Long);
       // System.out.println("Short String = " + Short + '\n');
          System.out.println(compare(allCombinations(Short)));
       //System.out.println("Longest SubString is " + LCM(Long,Short));
     }
 
    public StringBuffer getMyStr() {
        return myStr;
    }
 
    public void setMyStr(StringBuffer myStr) {
        this.myStr = myStr;
    }
 
}
